package com.ht.controller;

import com.ht.bean.Emp;
import com.ht.bean.Weekly;
import com.ht.service.WeeklyService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/weeklys")
public class WeeklyController {

    @Resource
    private WeeklyService weeklyService;

    //去周报页面
    @RequestMapping("/goweekly")
    private String goweekly(){
        return "weekly";
    }
    //去添加周报页面
    @RequestMapping("/goaddWeeklyNews")
    private String goaddWeeklyNews(){
        return "addWeeklyNews";
    }

    //查看周报详情
    @RequestMapping("/goLookWeeklyContent/{worklogId}")
    private String goLookWeeklyContent(Model model,@PathVariable Integer worklogId){
        List<Map> list = weeklyService.selectWeeklyByWorklogId(worklogId);
        model.addAttribute("list",list);
        System.out.println(list);
        return "LookWeeklyContent";
    }

    //查询所有周报信息
    @RequestMapping("/weeklyData")
    @ResponseBody
    public Map weeklyData(Integer page, Integer limit, Weekly weekly, Emp emp,String empId){
        List<Map> list = weeklyService.selectWeeklyData(empId,(page-1)*limit,limit,emp,weekly);
        System.out.println(list);
        Map map = new HashMap();
        map.put("code",0);
        map.put("msg","成功");
        map.put("count",weeklyService.selectWeeklyCount(empId,emp,weekly));
        map.put("data",list);
        return map;
    }

    /*
     *删除员工信息
     * @param
     * @return
     **/
    @RequestMapping("/deleteWeeklyId")
    @ResponseBody
    public Map deleteWeeklyIds(Integer worklogId){
        Map map = new HashMap();
        boolean bln =  weeklyService.deleteWeeklyId(worklogId);
        if (bln){
            map.put("msg","删除成功！");
        } else {
            map.put("msg","删除失败！");
        }
        return map;
    }

    /*
     *员工信息页面
     * @param
     * @return
     **/
    @RequestMapping("/addWeeklyNews")
    @ResponseBody
    public Map addWeeklyNews(Weekly weekly){
        Map map = new HashMap();
        boolean bln = weeklyService.insertWeeklyMsg(weekly);
        if (bln) {
            map.put("msg","新增成功。");
        } else {
            map.put("msg","新增失败。");
        }
        return map;
    }



}
